package com.example.kotlinlearn.kotlinLearn.test

import kotlinx.coroutines.runBlocking

object Player : PlayerInter{

    var isplaying = false

    val text = listOf<String>("1","11","111","1111","11111","111111","1111111","11111111","111111111","1111111111")

    init {
        println("播放器初始化中。。。")
        runBlocking {
            Thread.sleep(3000)
        }
        println("播放器初始化完毕")
    }

    override fun play() {
        println("播放器开始播放...")
        isplaying = true
        runBlocking {
            while (true) {
                Thread.sleep(40)
                for (i in 0..5){
                    println(text[(0..9).random()])
                }
                if (!isplaying) break
            }
        }
    }

    override fun pause() {
        println("播放器暂停播放...")
        isplaying = false
    }

    override fun stop() {
        println("播放器停止播放...")
        isplaying = false
    }

    override fun resume() {
        println("播放器重新播放...")
        println("歌曲资源释放...")
        play()
    }

    override fun nextSong() {
        println("下一首")
        play()
    }

    override fun beforeSong() {
        println("上一首")
        play()
    }

    override fun releasePlayer() {
        println("播放器销毁")
    }
}